package com.huike.clues.service.impl;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.dto.TbClueTrackRecordDto;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;


@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;
    /**
     * 添加跟进记录
     *
     * @param tbClueTrackRecordDto
     * @return
     */
    @Override
    public Boolean saveClueTrackRecord(TbClueTrackRecordDto tbClueTrackRecordDto) {
        //0.获取当前用户
        String createBy = SecurityUtils.getUsername();
        tbClueTrackRecordDto.setCreateBy(createBy);
        tbClueTrackRecordDto.setCreateTime(new Date());
        tbClueTrackRecordDto.setType("0");
        //1.添加跟进记录，
        tbClueTrackRecordMapper.saveClueTrackRecord(tbClueTrackRecordDto);
        //2.修改客户线索信息
        TbClue tbClue = new TbClue();
        String name = tbClueTrackRecordDto.getName();
        String sex = tbClueTrackRecordDto.getSex();
        Integer age = tbClueTrackRecordDto.getAge();
        String weixin = tbClueTrackRecordDto.getWeixin();
        Long clueId = tbClueTrackRecordDto.getClueId();
        String qq = tbClueTrackRecordDto.getQq();
        tbClue.setName(name);
        tbClue.setSex(sex);
        tbClue.setAge(age);
        tbClue.setWeixin(weixin);
        tbClue.setQq(qq);
        tbClue.setId(clueId);
        tbClue.setStatus("2");
        tbClueMapper.updateTbClue(tbClue);

        return true;
    }
}
